/*
 * @Description  :
 * @Autor        : guoxi
 * @Date         : 2022-08-18 16:58:29
 * @LastEditors  :
 * @LastEditTime : 2022-08-18 16:58:29
 * @FilePath     : \rpms\src\directives\permission\index.ts
 */
import { usePermissionStoreHook } from "/@/store/modules/permission";
import { Directive } from "vue";
import { storageLocal } from "/@/utils/storage";

export const auth: Directive = {
  mounted(el, binding) {
    const { value } = binding;
    if (value) {
      const authRoles = value;
      const authList = usePermissionStoreHook().buttonAuth;
      const hasAuth = (authList && authList.includes(authRoles)) ?? false;
      if (hasAuth) {
        el.style.opacity = 0;
        el.style.display = "none";
      }
      if((authRoles.indexOf('/project/manage-del')!=-1||authRoles.indexOf('/project/filings-del')!=-1) && storageLocal.getItem("rdms-info")?.username!='rdadmin'){
        el.style.opacity = 0;
        el.style.display = "none";
      }
    } else {
      throw new Error("need roles! Like v-auth=\"['admin','test']\"");
    }
  }
};
